<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org/">
	<head>
		<meta charset="utf-8">
		<title>layuiAdmin 网站用户</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" media="all">
		<link rel="stylesheet" th:href="@{/layuiadmin/style/admin.css}" media="all">
		<script type="text/javascript" th:src="@{/public/jquery-3.4.1.js}"></script>
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-card">
				<!-- 搜索栏div -->
				<div class="layui-form layui-card-header layuiadmin-card-header-auto">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">选择药品</label>
							<div class="layui-input-block">
			                    <select type="text" name="is_drugid" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">未选择</option>
			                        <option th:each="drug:${drugs}" th:value="${drug.drugDict_id}">[[${drug.drugDict_name}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">输入药品名</label><!--   -->
							<div class="layui-input-block">
								<input type="text" name="drug.drugDict_name" id="drugDict_name" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off"  
									style="position:absolute;z-index:2;width:86%;">
			                    <select type="text" id="SelectId-drugDict_name" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="drug:${drugs}" th:value="${drug.drugDict_id}">[[${drug.drugDict_name}]]</option>
			                    </select>
							</div>
						</div>
						
						
						<div class="layui-inline">
							<label class="layui-form-label">订单号</label>
							<div class="layui-input-block">
								<input type="text" name="is_order" id="is_order" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text" id="SelectId-is_order" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_order}">[[${item.is_order}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline" style="width: 398px;">
							<label class="layui-form-label">到达日期</label>
							<div class="layui-input-inline">
								<input type="text" name="is_arrivaltime_interval" id="is_arrivaltime_interval" 
									class="layui-input" placeholder=" - 区间 - " style="width: 294px;">
							</div>
						</div>
						
						<div class="layui-inline" style="margin-right: 0px;">
							<label class="layui-form-label">数量</label>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="is_num_min" lay-verify="gtZeroOrNull" lay-verType="tips" placeholder="￥" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">~</div>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="is_num_max" lay-verify="gtZeroOrNull" placeholder="￥" autocomplete="off" class="layui-input">
							</div>
						</div>
						
						<div class="layui-inline" style="margin-right: 0px;">
							<label class="layui-form-label">单价</label>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="is_price_min" lay-verify="gtZeroPointZero1OrNull" placeholder="￥" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">~</div>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="is_price_max" lay-verify="gtZeroPointZero1OrNull" placeholder="￥" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline" style="margin-right: 0px;">
							<label class="layui-form-label">总价</label>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="is_totalmoney_min" lay-verify="gtZeroPointZero1OrNull" placeholder="￥" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">~</div>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="is_totalmoney_max" lay-verify="gtZeroPointZero1OrNull" placeholder="￥" autocomplete="off" class="layui-input">
							</div>
						</div>
						
						<div class="layui-inline" style="width: 398px;">
							<label class="layui-form-label">生产日期</label>
							<div class="layui-input-inline">
								<input type="text" name="is_startdate_interval" id="is_startdate_interval" 
									class="layui-input" placeholder=" - 区间 - " style="width: 294px;">
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">批次</label>
							<div class="layui-input-block">
								<input type="text" name="is_batch" id="is_batch" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text"  id="SelectId-is_batch" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_batch}">[[${item.is_batch}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">批号</label>
							<div class="layui-input-block">
								<input type="text" name="is_batchnum" id="is_batchnum" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text" id="SelectId-is_batchnum" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_batchnum}">[[${item.is_batchnum}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">说明</label>
							<div class="layui-input-block">
								<input type="text" name="is_remark" id="is_remark" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text" id="SelectId-is_remark" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_remark}">[[${item.is_remark}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline" style="width: 398px;">
							<label class="layui-form-label">有效日期</label>
							<div class="layui-input-inline">
								<input type="text" name="is_enddate_interval" id="is_enddate_interval" 
									class="layui-input" placeholder=" - 区间 - " style="width: 294px;">
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">产地</label>
							<div class="layui-input-block">
								<input type="text" name="is_production" id="is_production" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text" id="SelectId-is_production" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_production}">[[${item.is_production}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">状态</label>
							<div class="layui-input-block">
								<select name="is_state">
									<option value="">未选择</option>
									<option value="等待验收">等待验收</option>
									<option value="已验收">已验收</option>
								</select>
							</div>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">验收人</label>
							<div class="layui-input-block">
								<select name="is_confirmid">
									<option value="">未选择</option>
									<option th:each="user:${users}" th:value="${user.user_id}">[[${user.realname}]]</option>
								</select>
							</div>
						</div>

						<div class="layui-inline" style="width: 398px;">
							<label class="layui-form-label">验收时间</label>
							<div class="layui-input-inline">
								<input type="text" name="is_completetime_interval" id="is_completetime_interval" 
									class="layui-input" placeholder=" - 区间 - " style="width: 294px;">
							</div>
						</div>

						<div class="layui-inline" style="width: 658px;">
							<label class="layui-form-label">对应采购单</label>
							<div class="layui-input-block">
								<select name="is_dp_id">
									<option value="">未选择</option>
									<option th:each="item:${drugpurchases}" th:value="${item.dp_id}">
[[${item.dp_id}]]-[[${#dates.format(item.dp_createtime,'yyyy-MM-dd HH:mm:ss')}]]---[[${item.drug.drugDict_name}]]---预计数量:[[${item.dp_num}]]---预计单价:[[${item.dp_price}]]---[[${item.dp_state}]]
									</option>
								</select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">存放仓库</label>
							<div class="layui-input-block">
								<select name="is_roomid">
									<option value="">未选择</option>
									<option th:each="storehouse:${storehouses}" th:value="${storehouse.store_id}">[[${storehouse.store_name}]]</option>
								</select>
							</div>
						</div>

						<!-- 按钮区域 -->
						<div class="layui-inline" style="margin-left: 40px;">
							<!-- 提交按钮 -->
							<button class="layui-btn btn-submit-instock" lay-submit lay-filter="LAY-instock-front-submit">
								<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
							</button>
							<!-- 重置按钮 -->
							<button class="layui-btn btn-submit-instock" lay-submit lay-filter="LAY-instock-front-reset">
								<i class="layui-icon layui-icon-refresh-3 layuiadmin-button-btn"></i>
							</button>
						</div>
					</div>
				</div>
				
				<div class="layui-card-body">
					<!-- 表格上的按钮组 -->
					<div style="padding-bottom: 10px;">
						<button class="layui-btn layui-btn-danger btn-submit-instock" data-type="batchdel">删除</button>
						<button class="layui-btn btn-submit-instock" data-type="add">添加</button>
					</div>

					<!-- 表格主体 -->
					<table id="instock-table" lay-filter="instock-table"></table>
				</div>
				
				<!-- 设置样式的js代码 -->
				<script type="text/html" id="imgTpl">
					<img style="display: inline-block; width: 50%; height: 100%;" src= {{ d.avatar }}>
        		</script>
       			<!-- 设置操作栏的按钮样式 -->
				<script type="text/html" id="table-instock-operatecolumn">
					<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" style="background-color:#6faeff;"><i class="layui-icon layui-icon-edit"></i>编辑</a>
					<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        		</script>
       			<!-- 设置操作栏的按钮样式 -->
       			<!-- 注意： {{d.id}}、{{d.title}} 是动态内容，它对应数据接口返回的字段名。除此之外，你还可以读取到以下额外字段：
						序号：{{ d.LAY_INDEX }} （该额外字段为 layui 2.2.0 新增）
 						由于模板遵循 laytpl 语法（建议细读 laytpl文档 ），因此在模板中你可以写任意脚本语句（如 if else/for等）： -->
       			<script type="text/html" id="buttonTpl">
				</script>
			</div>
		</div>

		<!-- 引入layui框架 -->
		<script th:src="@{/layuiadmin/layui/layui.js}"></script>
		<!-- 引入公共layui代码 -->
		<script type="text/javascript" th:src="@{/public/warehouse/publicsetting.js}"></script>
		<script>
			//启动layui语法：laydate添加日期插件功能
			layui.use('laydate', function() {
				//启动绑定时间组件
				var laydate = layui.laydate;
				//同时多选绑定，会有闪烁bug，所以使用id选择器绑定
				laydate.render({
					elem: '#is_startdate_interval',//指定元素
					range: "~",//开启区间模式
				});
				laydate.render({
					elem: '#is_enddate_interval',
					range: "~"
				});
				laydate.render({
					elem: '#is_arrivaltime_interval',
					type: 'datetime',//指定类型
					range: "~"
				});
				laydate.render({
					elem: '#is_completetime_interval',
					type: 'datetime',//指定类型
					range: "~"
				});
			});

			//启动layui语法：config全局配置
			layui.config({
				base: '[[@{/layuiadmin/}]]' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'warehouse/instock', 'table'], function() {//调用layui的js文件，注意路径，直接在/layuiadmin/modules/文件夹下
				//生成标签的对应对象
				var $ = layui.$,
					form = layui.form,
					table = layui.table;
			
				//监听重置搜索
				form.on('submit(LAY-instock-front-reset)', function(data) {
					location.reload();
				});

				//监听搜索
				form.on('submit(LAY-instock-front-submit)', function(data) {
					var field = data.field;

					//执行重载，重新加载表格数据
					table.reload('instock-table', {
						where: field
					});
				});

				//事件。当标签的 data-type=""字段等于这里的字段名时，执行对应方法
				var active = {
					//批量删除按钮的事件
					batchdel: function() {
						var checkStatus = table.checkStatus('instock-table'),//获得指定表格的选中行状态
							checkData = checkStatus.data; //得到选中行的数据
						if (checkData.length === 0) {//判断是否有选择行
							return layer.msg('请选择数据');
						}
						layer.prompt({//弹出输入口令窗口
							formType: 1,
							value: '',//默认值
							title: '敏感操作，请验证口令'
						}, function(value, index, elem) {//elem代表元素
							layer.close(index); //关闭口令窗口
							console.log(value); //得到口令窗口输入框的值

							layer.confirm('确定删除吗？', function(index) {
								console.log(checkData);
								//定义为数组
								var ids=[];
								$.each(checkData,function(key,item){
									console.log(key+" " +item+"        "+item.is_id);
									ids.push(item.is_id);//加入id值
								});
								$.ajax({
									url: getRootPath() + "/warehouse/instock/delete",
									type:"POST",//请求方式(GET | POST)
									data:{
										ids,//键名称和@RequestParam("键[]") 的值相同
									},
									success:function(data){
										layer.msg(data);//提示信息
										console.log(data);
										table.reload('instock-table');//重新加载表格
									},
								});
								//执行 Ajax 后重载
								/*
								admin.req({
								  url: 'xxx'
								  //,……
								});
								*/
							});
						});
					},
					//添加按钮的事件
					add: function() {
						layer.open({//弹窗功能，窗口内容为一个独立的网页
							type: 2,
							title: '新增入库单',
							content: '[[@{/warehouse/instock/editpage}]]',//网页地址
							maxmin: true,
							area: ['1100px', '730px'],//定义弹窗的大小
							btn: ['确定', '取消'],//定义弹窗的按钮
							yes: function(index, layero) {
								var iframeWindow = window['layui-layer-iframe' + index],
									submitID = 'LAY-instock-front-submit',
									submit = layero.find('iframe').contents().find('#' + submitID);

								//监听提交
								iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
									var field = data.field; //获取提交的字段

									if(field.is_dp_id==null || field.is_dp_id==""){
										layer.msg('↓↓↓请选择采购单↓↓↓');//提示信息
									}else{
										//提交 Ajax 成功后，静态更新表格中的数据
										$.ajax({
											url: getRootPath() + "/warehouse/instock/insertone",
											type: "POST", //请求方式(GET | POST)
											contentType: 'application/json;charset=UTF-8', //发送信息的数据类型
											data: JSON.stringify(data.field),
											success: function(result) {
												layer.msg(result);//提示信息
												console.log(result);
												//重新加载表格
												table.reload('instock-table', {});
											},
										});

										table.reload('LAY-instock-front-submit'); //数据刷新
										layer.close(index); //关闭弹层
										
									}
								});
								
								submit.trigger('click');
							}
						});
					}
				};
				
				//不知道是什么
				$('.layui-btn.btn-submit-instock').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
			});
		</script>
	</body>
</html>
